package flyrestaurant.jcy.service;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

import android.content.Context;

public class ConfigService {
	static final String CONFIG_FILE = "config";
	
	Context context;
	
	public ConfigService(Context context) {
		this.context = context;
	}
	
	public Properties read() throws IOException {
		ceeateFile();
		Properties config = new Properties();
		FileInputStream fis = context.openFileInput(CONFIG_FILE);
		config.load(fis);
		fis.close();
		return config;
	}
	
	public void write(Properties config) throws IOException {
		ceeateFile();
		FileOutputStream fos = context.openFileOutput(CONFIG_FILE, context.MODE_PRIVATE);
		config.store(fos, null);
		fos.close();
	}
	
	void ceeateFile() throws IOException {
		File file = new File(context.getFilesDir(),CONFIG_FILE);
		if (!file.exists())
			file.createNewFile();
	}
}